#coding:UTF-8
"""

"""

#import codecs
import re

version = "0.1"

#http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496969
#convert string to hex
def toHex(s):
    lst = []
    for ch in s:
        hv = hex(ord(ch)).replace('0x', '')
        if len(hv) == 1:
            hv = '0'+hv
        lst.append(hv)

    return reduce(lambda x,y:x+y, lst)

# read file
# words 
# -+
#  + [english word][translation][pronunciation][level]
#  + [english word][translation][pronunciation][level]
#  + .
#  + .
#  + [english word][translation][pronunciation][level]
def docReader(file):
    content = file.read()
    content = unicode(content, 'UTF-16')
    list = content.split('+')
    words = [] # the zero is empty
    
    for e in list[1:len(list)]:
        arr = ['','','','']
        for line in e.split('\n'):
            if len(line) > 0:
                if line[0] == '#':
                    if len(line) > 1:
                        arr[1] = arr[1] + line[1:]
                elif line[0] == '&':
                    if len(line) > 1:
                        arr[2] = arr[2] + line[1:]
                elif line[0] == '$':
                    if len(line) > 1:
                        arr[3] = arr[3] + line[1:]
                else:
                    arr[0] = arr[0] + line
        words.append(arr)
    return words

def strReader(str):
    #content = file.read()
    #content = unicode(content, 'UTF-16')
    content = str
    list = content.split('+')
    words = [] # the zero is empty
    
    for e in list[1:len(list)]:
        arr = ['','','','']
        for line in e.split('\n'):
            if len(line) > 0:
                if line[0] == '#':
                    if len(line) > 1:
                        arr[1] = arr[1] + line[1:]
                elif line[0] == '&':
                    if len(line) > 1:
                        arr[2] = arr[2] + line[1:]
                elif line[0] == '$':
                    if len(line) > 1:
                        arr[3] = arr[3] + line[1:]
                else:
                    arr[0] = arr[0] + line
        words.append(arr)
    return words

if __name__=="__main__":
    file = open('words.txt', 'rb')
    array = docReader(file)
    try:
        file.close()
    except:
        pass
    if array != None:
        for word in array:
            #for w in word:
            print word[2].encode('utf-8')
            for i in word[2].encode('utf-8'):
                print ord(i),
            print 
